#include<stdlib.h>
#include<time.h>
#include<vector.h>
#include "molCluster.h"


double mt() {


        return (double)(rand()%1000001)/1000000.0;

}

int compareDouble(const void *num1, const void *num2) {
  	double a, b;
        a = (double)(*(double*)num1);
        b = (double)(*(double*)num2);

  	if (a < b) return -1;
  	if (a == b) return  0;
  	if (a > b) return  1;
}

int compareMolCluster(const void *molCluster1, const void *molCluster2) {
        double a, b;
        a = (double)(*(molCluster*)molCluster1).properties[0];
        b = (double)(*(molCluster*)molCluster2).properties[0];

        if (a < b) return -1;
        if (a == b) return  0;
        if (a > b) return  1;
}

void sortDoubleVector( vector<double>& a ) {

	int i;
	double* array = new double[a.size()];
	for(i=0; i<a.size(); i++) array[i] = a[i];

        qsort( array, a.size(), sizeof(double), compareDouble ); 
	
	for(i=0; i<a.size(); i++) a[i] = array[i];
	delete [] array;
}


void sortMolClusterVector( vector<molCluster>& a ) {

        int i;
        molCluster* array = new molCluster[a.size()];
        for(i=0; i<a.size(); i++) array[i] = a[i];

        qsort( array, a.size(), sizeof(molCluster), compareMolCluster );

        for(i=0; i<a.size(); i++) a[i] = array[i];
        delete [] array;
}

